package com.UI;

import java.util.ArrayList;
import java.util.List;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import android.content.Context;


/** Author :  Anirudh, Mohammed
 * 
 * ListView GUI Optimization
 * Implements a custom ListView for themes,background and style
 * 
 */

class ToDoAdapter extends ArrayAdapter<RetriveToDoInfo> {

        private static List<RetriveToDoInfo> records;

        public 	ToDoAdapter(Context context, int textViewResourceId, List<RetriveToDoInfo> records) {
                super(context, textViewResourceId, records);
                this.records = records;
        }
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
                View v = convertView;
                if (v == null) {
                    LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

                    v = vi.inflate(R.layout.todo_row, null);
                }
                RetriveToDoInfo todo = records.get(position);
                if (todo != null) {
                        TextView title_todo = (TextView) v.findViewById(R.id.todotitle);
                        title_todo.setTextAppearance( getContext(), R.style.ToDoTitle );
                        
                        if (title_todo != null) {
                        	title_todo.setText(todo.getTitle());                            
                        	}

                        TextView course_todo = (TextView) v.findViewById(R.id.courseToDo);
                        course_todo.setTextAppearance( getContext(), R.style.ToDoCourse );
                        
                        if (course_todo != null) {
                        	course_todo.setText("(" + todo.getCourse() + ")");      
                        }
                        
                        
                        TextView date_todo = (TextView) v.findViewById(R.id.dateToDo);
                        date_todo.setTextAppearance( getContext(), R.style.ToDoDateTime );
                        
                        if (date_todo != null) {
                        	date_todo.setText(todo.getDate());      
                        }          
                        

                        TextView time_todo = (TextView) v.findViewById(R.id.timeToDo);
                        time_todo.setTextAppearance( getContext(), R.style.ToDoDateTime );
                        
                        if (time_todo != null) {
                        	time_todo.setText(todo.getTime());      
                        }   
                        
                
        }
                return v;
     }    
}     